Skip to content

fix(browser): remove a closed window from the default context instead of a copy of its targets - #365

Closed
route wants to merge 2 commits into
mainfrom
fix-close-window
Closed

route wants to merge 2 commits into
mainfrom
fix-close-window

Conversation

@route

@route route commented Nov 19, 2026

Copy link
Copy Markdown
Member

Context#targets returns a copy of the hash since rubycdp/ferrum#707. close_window deleted the closed window from that copy, which changed nothing. page.close is async, so the window stayed listed until Chrome reported it destroyed. In that gap:

  • Capybara::Window#exists? stayed true and #closed? stayed false
  • switch_to_window and within_window with the closed window raised Ferrum::BrowserError: Session with given id not found. instead of Ferrum::NoSuchPageError
  • Window#close on another window didn't switch back to the original one

close_window now removes the window with default_context.delete_target. browser.targets comes from the default context, so it's removed from the same place as before.

Against Ferrum main (99b6c17):

  • bundle exec rspec spec/capybara_spec.rb -e window -e Window: 64 examples, 0 failures, 2 pending, including the 6 that failed
  • bundle exec rspec spec/driver_spec.rb -e window: 22 examples, 0 failures, 5 pending

… of a copy of its targets

Ferrum 0.21 returns a copy from Context#targets, so deleting from it kept a closed window listed until Chrome reported it destroyed: exists? stayed true and switching to it raised BrowserError instead of NoSuchPageError.
@route

route commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Superseded by #366.

@route route closed this Nov 19, 2026
@route
route deleted the fix-close-window branch November 19, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant